<?php

class User extends TUser
{	
	private $userRecord;
	
	public function setUserRecord($_userRecord)
	{
		$this->userRecord = $_userRecord;
		$this->setState('first_name', $_userRecord->getFirstName());
		$this->setState('last_name', $_userRecord->getLastName());
		$this->setState('email', $_userRecord->getEmail());
		$this->setState('login', $_userRecord->getLogin());
	}
	
	public function getUserRecord()
	{
		return $this->userRecord;
	}
	
	public function getFullName()
	{
		$full_name = $this->getState('first_name').' '.$this->getState('last_name');
		if($full_name === '' || $full_name === ' ')
			$full_name = $this->getState('email');
		return $full_name;
	}
	
	public function getLogin()
	{
		return $this->getState('login');
	}

	// checking roles
	public function getIsAdmin()
	{
		return $this->isInRole(RoleManager::$ADMIN_ROLE);
	}
	
	public function getIsParticipant()
	{
		return $this->isInRole(RoleManager::$PARTICIPANT_ROLE) || $this->getIsAdmin();
	}

	public function getIsOrganizer()
	{
		return $this->isInRole(RoleManager::$ORGANIZER_ROLE) || $this->getIsAdmin();
	}
	
	public function getIsCommittee()
	{
		return $this->isInRole(RoleManager::$COMMITTEE_ROLE) || $this->getIsAdmin();
	}
	
	public function saveToString()
	{
		$a=array($this->getUserRecord()->id, parent::saveToString());
		return serialize($a);
	}

	public function loadFromString($data)
	{
		if(!empty($data))
		{
			list($id,$str)=unserialize($data);
			//$this->id = $id;
			return parent::loadFromString($str);
		}
		else
			return $this;
	}
}

?>